var SComet = new function() {
	this.getSComet = function() {
		return new function() {
			this.status = 0;
			this.id = 0;
			this.tail = "scomet";
			this.count = 0;
			this.getAjaxRequest = function() {
				var xmlHttp;
				try {
					xmlHttp = new XMLHttpRequest();
				} catch (e) {
					try {
						xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
					} catch (e) {
						return null;
					}
				}
				return xmlHttp;
			};
			this.send = function(message) {
				this.ajax("message", "?id=" + this.id + "&message="
						+ this.formatText(encodeURI(message)) + "&count="
						+ ++this.count, function(message, conn) {
					if (message.length != 0 && message.charAt(0) == 'c') {
						conn.status = 0;
						conn.id = 0;
					}
				});
			};
			this.link = function() {
				this.ajax("request", "?count=" + ++this.count, function(
						message, conn) {
					conn.id = parseInt(message.substring(2, message.length));
					conn.status = 1;
					conn.connection(conn);
				});
			};
			this.close = function() {
				this.status = 0;
				this.id = 0;
				this.ajax("close", "?id=" + this.id + "&count=" + ++this.count,

				function(message, conn) {
				});
			};
			this.callBack = null;
			this.connection = function() {
				if (this.status == 0) {
					return;
				}
				this.ajax("connection", "?id=" + this.id + "&count="
						+ ++this.count, function(message, conn) {
					if (message.charAt(0) == 'c') {
						conn.status = 0;
						conn.id = 0;
					} else {
						conn.callBack(message.substring(2, message.length));
						conn.connection(conn);
					}
				});
			};
			this.self = this;
			this.ajax = function(url, attr, callBack) {
				var ajaxRequest = this.getAjaxRequest();
				var self = this.self;
				ajaxRequest.onreadystatechange = function() {
					if (ajaxRequest.readyState == 4) {
						callBack(ajaxRequest.responseText, self);
					}
				};
				ajaxRequest.open("GET", url + "." + this.tail + attr, true);
				ajaxRequest.send(null);
			};
			this.formatText = function(message) {
				return message.replace(/\//gm, "//").replace(/#/gm, "/s")
						.replace(/\+/gm, "/p").replace(/&/gm, "/a");
			};
		};
	};
};